/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pl.put.dcs_modeler.loaders;


import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Logger;

import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
import pl.put.dcs.core.utils.serializer.SerializeManager;
import pl.put.dcs_modeler.exceptions.dcsModelerIOException.DCSModelerObjectIOException;
import pl.put.model.computingObject.ComputingObject;
/**
 *
 * @author LukaszR
 */
public class ComputingObjectLoader
{
    public static Logger log = Logger.getLogger( ComputingObjectLoader.class.getName() );

    public ComputingObject getComputingObjectFromFile( String path ) throws DCSModelerObjectIOException
    {
        ComputingObject co = null;
        try
        {
            
            File file = new File( path );
            FileObject fo = FileUtil.createData( file );
            InputStream is = fo.getInputStream();
            co = getComputingObjectFromFile( is );
            is.close();
            
        }
        catch ( IOException ex )
        {
            DCSModelerObjectIOException retEx = new DCSModelerObjectIOException( path, ex.getMessage() );
            retEx.setStackTrace( ex.getStackTrace() );
            throw retEx;
        }
        return co;
    }
    
    public ComputingObject getComputingObjectFromFile( InputStream is )
    {
        ComputingObject co = null;
        
        SerializeManager sm = new SerializeManager();
        sm.init();
        co = ( ComputingObject )sm.unSerializeFromFile( is );
        
        return co;
    }

}
